package com.lixy.demo.springcloud.ch7_2.controller;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.client.RestTemplate;

import org.springframework.beans.factory.annotation.Autowired;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import com.lixy.demo.springcloud.ch7_2.vo.User;

@RestController
public class MovieController {

	@HystrixCommand(fallbackMethod="findByIdFallback")
	@GetMapping("/user/{id}")
	public User findById( @PathVariable Long id ) {
		return this.restTemplate.getForObject( "http://microservice-provider-user/" + id, User.class );
	}
	
	public User findByIdFallback( Long id ) {
		User user = new User();
		user.setId( -1L );
		user.setName( "默认用户" );
		return user;
	}
	
	@Autowired
	private RestTemplate restTemplate;
}
